package com.cskaoyan.servlet;

import com.cskaoyan.bean.MarketCategory;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;

import com.cskaoyan.service.AdminCategoryService;
import com.cskaoyan.service.AdminCategoryServiceImpl;
import com.cskaoyan.util.JacksonUtil;
import lombok.SneakyThrows;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/admin/category/*")
public class AdminCategoryServlet extends WdBaseServlet{
    private AdminCategoryService adminBrandService = new AdminCategoryServiceImpl();
    private BaseRespVo list(HttpServletRequest request, HttpServletResponse response) {
        CommonData data = adminBrandService.query();
        return BaseRespVo.ok(data);
    }
    private BaseRespVo l1(HttpServletRequest request, HttpServletResponse response){
        CommonData data = adminBrandService.queryL1();
        return BaseRespVo.ok(data);
    }

    @SneakyThrows
    private BaseRespVo create(HttpServletRequest request, HttpServletResponse response){
        String s = request.getReader().readLine();
        MarketCategory marketCategory = JacksonUtil.read(s, MarketCategory.class);
        MarketCategory data = adminBrandService.create(marketCategory);
        return BaseRespVo.ok(data);
    }

    @SneakyThrows
    private BaseRespVo update(HttpServletRequest request, HttpServletResponse response){
        String s = request.getReader().readLine();
        MarketCategory marketCategory = JacksonUtil.read(s, MarketCategory.class);
        adminBrandService.update(marketCategory);
        return BaseRespVo.ok();
    }

    @SneakyThrows
    private BaseRespVo delete(HttpServletRequest request, HttpServletResponse response){
        String s = request.getReader().readLine();
        MarketCategory marketCategory = JacksonUtil.read(s, MarketCategory.class);
        adminBrandService.delete(marketCategory);
        return BaseRespVo.ok();
    }
}
